package com.vitalfit.handler.handlerImpl;

import com.vitalfit.handler.UserHandler;
import com.vitalfit.model.dto.HandleDTO;
import com.vitalfit.model.entity.user.Trainer;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@RequiredArgsConstructor
@Component
public class TrainerHandler implements UserHandler<Trainer> {

    private final PasswordEncoder passwordEncoder;
    @Override
    public void handle(Trainer trainer, HandleDTO handleDTO) {
        if (handleDTO.getStarRating() != null) {
            trainer.setStarRating(handleDTO.getStarRating());
        }
        if (handleDTO.getName() != null && !handleDTO.getName().isEmpty()) {
            trainer.setName(handleDTO.getName());
        }

        if (handleDTO.getPassword() != null && !handleDTO.getPassword().isEmpty()) {
            String encodedPassword = passwordEncoder.encode(handleDTO.getPassword());
            trainer.setPassword(encodedPassword);
        }

        if (handleDTO.getEmail() != null && !handleDTO.getEmail().isEmpty()) {
            trainer.setEmail(handleDTO.getEmail());
        }
    }
}